package com.otv.cliente.dao;

import java.util.List;

import com.otv.model.Cliente;
import org.hibernate.SessionFactory;



/**
 * Class ClienteDAO.
 */
public class ClienteDAO implements IClienteDAO {
	
	
	/** El/la session factory. */
	private SessionFactory sessionFactory;

	/**
	 * Get Hibernate Session Factory.
	 *
	 * @return SessionFactory - Hibernate Session Factory
	 */
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	/**
	 * Set Hibernate Session Factory.
	 *
	 * @param sessionFactory un(a) nuevo(a) session factory
	 */
	public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

	


	@Override
	public void addCliente(Cliente cliente) {
		getSessionFactory().getCurrentSession().save(cliente);
	}


	@Override
	public void updateCliente(Cliente cliente) {
		getSessionFactory().getCurrentSession().update(cliente);
	}


	@Override
	public void deleteCliente(Cliente cliente) {
		getSessionFactory().getCurrentSession().delete(cliente);
	}


	@Override
	public Cliente getClienteById(int id) {
		return (Cliente) getSessionFactory().getCurrentSession().createQuery("from Cliente where id=?").setParameter(0,id).list().get(0);
	}


	@Override
	public List<Cliente> getClientes() {
		return getSessionFactory().getCurrentSession().createQuery("from Cliente").list();
	}

}
